import {Router} from 'express'
const router = Router();
const qs = require('qs');
import axios from '../src/plugins/axios';

const config = require('../config.json');

const apiUrl = config.apiUrl;

/*
 * 获取用户信息
 * */
router.get('/api/h5/token/userinfo', function (req, res) {
    let query = req.query;

    //http://order-lite.dev.meoin.cn
    axios.get(`${apiUrl}/api/token/userinfo`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    }).catch(e => {
        console.log(e)
    })
});


/*
 * 获取排队信息
 * */
router.get('/api/h5/customer/check-queue-order', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/check-queue-order`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    }).catch(e => {
        console.log(e.response.data)
    })
});

/*
 * 扫描桌台获取店铺信息
 * */
router.get('/api/h5/customer/scan-order', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/scan-order`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 优惠券列表
 * */
router.get('/api/h5/customer/coupon', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/coupon`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 订单列表列表
 * */
router.get('/api/h5/customer/order', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/order`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 订单详情
 * */
router.get('/api/h5/customer/order/detail', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/order/detail`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 菜品信息
 * */
router.get('/api/h5/customer/cuisine', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/cuisine`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 预约创建订单
 * */
router.post('/api/h5/customer/pre-cuisine', function (req, res) {
    let body = req.body;
    axios.post(`${apiUrl}/api/customer/pre-cuisine`, body).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 获取预约订单详细
 * */
router.get('/api/h5/customer/pre-cuisine/detail', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/pre-cuisine/detail`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 确定订单
 * */
router.post('/api/h5/customer/order', function (req, res) {
    let body = req.body;
    axios.post(`${apiUrl}/api/customer/order`, body).then(rs => {
        res.json(rs.data)
    }).catch(e => {
        console.log(e.response.data)
    })
});

/*
 * 加菜确定订单
 * */
router.post('/api/h5/customer/order/extra', function (req, res) {
    let body = req.body;
    axios.post(`${apiUrl}/api/customer/order/extra`, body).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 用餐中列表
 * */
router.get('/api/h5/customer/dining', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/dining`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});


/*
 * 呼叫服务
 * */
router.get('/api/h5/customer/store-service', function (req, res) {
    let query = req.query;

    axios.get(`${apiUrl}/api/customer/store-service`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 呼叫服务
 * */
router.post('/api/h5/customer/store-service', function (req, res) {
    let body = req.body;

    axios.post(`${apiUrl}/api/customer/store-service`, body).then(rs => {
        res.json(rs.data)
    })
});


/*
 * 预约首页
 * */
router.get('/api/h5/customer/queue', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/queue`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 确定人数及桌台类型
 * */
router.post('/api/h5/customer/queue', function (req, res) {
    let body = req.body;
    axios.post(`${apiUrl}/api/customer/queue`, body).then(rs => {
        res.json(rs.data)
    })
});

/*
 * 排队中详细
 * */
router.get('/api/h5/customer/queue/detail', function (req, res) {
    let query = req.query;
    axios.get(`${apiUrl}/api/customer/queue/detail`, {
        params: query
    }).then(rs => {
        res.json(rs.data)
    }).catch(e => {
        console.log(e)
    })
});

export default router